package com.wwm.makerandroid.makerandroid.View.Adapter;

import static com.wwm.makerandroid.makerandroid.Utils.ParseUtil.getStateString;
import static com.wwm.makerandroid.makerandroid.Utils.ParseUtil.getTypeString;

import android.annotation.SuppressLint;
import android.support.annotation.NonNull;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lipiao.makerandroid.R;
import com.wwm.makerandroid.makerandroid.Bean.RespondBean.RecordBean;
import com.wwm.makerandroid.makerandroid.Bean.RespondBean.RecordBean2;
import com.wwm.makerandroid.makerandroid.Utils.ParseUtil;

import java.util.List;


//请假申请适配器（top）——recycleView+cardView
public class ApplyRecordAdapter2 extends RecyclerView.Adapter<ApplyRecordAdapter2.ContactViewHolder> {


    View applyView;
    //MyAdapter的成员变量contactInfoList, 这里被用作数据的来源
    private List<RecordBean2.DataBean> recordBeanList;

    //构造函数
    public ApplyRecordAdapter2(List<RecordBean2.DataBean> recordBeanList) {
        this.recordBeanList = recordBeanList;
    }


    //重写3个抽象方法
    @NonNull
    @Override
    public ApplyRecordAdapter2.ContactViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

        View itemView = LayoutInflater.from(viewGroup.getContext()).
                inflate(R.layout.tongji_card_item, viewGroup, false);
        return new ContactViewHolder(itemView);

    }

    //    fixme 预览信息不显示  点击事件正常  fix 预览信息不知道为什么 字体颜色被改为白色了 和背景相同看不见
    @SuppressLint("ResourceAsColor")
    @Override
    public void onBindViewHolder(@NonNull ApplyRecordAdapter2.ContactViewHolder contactViewHolder, int i) {
//        citybeanList中包含的都是citybean类的对象
//        通过其get()方法可以获得其中的对象
        RecordBean2.DataBean recordBean = recordBeanList.get(i);
        contactViewHolder.name.setText(recordBean.getName());
        contactViewHolder.dept.setText(recordBean.getDept());
        contactViewHolder.role.setText(ParseUtil.getRoleString(recordBean.getRole()));



        //todo
//        点击item 不同地方跳转到对应页面
    }

    @Override
    public int getItemCount() {
        return recordBeanList.size();
    }

    //重点：该泛型必须是 自定义的适配器(如MyAdapter).ViewHolder
    class ContactViewHolder extends RecyclerView.ViewHolder {
        //create the viewHolder class
//        protected CardView type;
        protected TextView name;
        protected TextView dept;
        protected TextView role;



        public ContactViewHolder(View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.tongji_name);
            dept = itemView.findViewById(R.id.tongji_dept);
            role = itemView.findViewById(R.id.tongji_role);
        }

    }

//    //有关监听（外部调用）
//    public void setOnItemClickListener(ApplyRecordAdapter.OnItemClickListener onItemClickListener) {
//        this.onItemClickListener = onItemClickListener;
//    }
//
//    private OnItemClickListener onItemClickListener= (view, position) -> System.out.println("qweqweqweqwe点击");
//
//    /**
//     * 自定义监听回调接口，RecyclerView 的 单击事件
//     */
//    public interface OnItemClickListener {
//        void onItemClick(View view, int position);
//    }

    View.OnClickListener clickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            System.out.println("qweqwe点击");
        }
    };


}//adapter.class